$(document).ready(function(){
    var ccn = $('#concern');
    var doConcern = function(){
        concernAction(1, ccn, function(ele){
            ele.text('-取消关注');
        });
    };
    var cancelConcern = function() {
        concernAction(0, ccn, function(ele){
            ele.text('+加关注');
        })
    }
	$.ajax({
		type:'POST',
		url:path+'/tutorinfo/detail/'+id,
		dataType:'json',
		success:function(json){
            var info = json.info;
			$('#uname').text(info.uname);
			$('#schoolName').text(info.schoolName);
			$('#area').text(info.area);
			$('#way').text(getTeachWay(info.way));
			$('#schedule').text(pareSchedule(info.schedule));
            var concern = json.concerned;
            switch(concern) {
                case 0:
                    ccn.text('+加关注');
                    ccn.toggle(doConcern, cancelConcern);
                    break;
                case 1:
                    ccn.text('-取消关注');
                    ccn.toggle(cancelConcern, doConcern);
                    break;
                case 2:
                    ccn.hide();
                    break;
            }
		}
	});

    function concernAction(action, actionElement, cb) {
        AjaxRequest(path+'/concern/action',{id:id,a:action}, function(json) {
            if(action == 1) {
                InfoPanel.show('添加成功','i', 1000);
            } else {
                InfoPanel.show('取消成功', 'i', 1000);
            }
            cb(actionElement);
        });
    }
});
